  
const _baseUrl='https://www.ptcxmy.com'
//const _baseUrl='http://htkjapp.v5.idcfengye.com'
  /**
   * 网络请求
   */
  const request=(url, data={},  method)=> {
    // wx.showLoading({
    //   title: '加载中',
    //   mask: true,
    // })
    var header={}
    var userInfo= wx.getStorageSync('userInfo')
    if (userInfo) {
     data.userId=userInfo.userId
    }
    var locationInfo=wx.getStorageSync('locationInfo')
    if(locationInfo){
      data.city=locationInfo.address_component.city
      data.area=locationInfo.address_component.district
      data.latitude=locationInfo.location.lat
      data.situation=locationInfo.location.lng
    }
    return new Promise((resolve, reject) => {
      wx.request({
        url: _baseUrl+url,
        data: data,
        header: header,
        method: method,
        success: (res => {
          wx.hideLoading()
          if (res.statusCode === 200) {
            //200: 服务端业务处理正常结束
            if (res.data.code === 401) {
              wx.navigateTo({
                url: '/pages/login/index',
              })
            }
            if (res.data.code != 0) {
              wx.showToast({
                title: res.data.message,
                icon:'none',
                duration:1500,
                mask:true,
              })
              return false
            }
            resolve(res.data)
          } else {
           
            reject(res.data)
          }
        }),
        fail: (res => {
         
          reject(res.data)
        })
      })
    })
  }


  module.exports ={
    request
  }